// 拓展作业:
// 自行封装一个读取文件的函数 read, 实现以下效果:

// read(path.join(__dirname, 'public/index.html')).then(data => {}).catch(err => {})
// const htmlData = await read(path.join(__dirname, 'public/index.html'))
// const htmlStr = htmlData.toString()
// const jsData = await read(path.join(__dirname, 'public/index.js'))
// const jsStr = jsData.toString()
// const htmlResult = htmlStr.replace(/[\r\n]/g, '').replace(/\s+/g, ' ')
// const jsResult = jsStr.replace(/[\r\n]/g, '').replace(/\s+/g, ' ').replace(/console.log\(.+?\)/g, '')
// fs.writeFile(path.join(__dirname, 'dist/index.html'), htmlResult + `<script>${jsResult}</script>`, err => {
//   console.log(err)
// })
// function read() {}
const fs = require('fs')
const path = require('path')
function read(way) {
    return new Promise((reslove, reject) => {
        fs.readFile(way, (err, data) => {
            if (err) return reject(err)
            reslove(data.toString())
        })
    })
}
async function render() {
    const htmlStr = await read(path.join(__dirname, '02_主观题/01_压缩 CSS 代码/01_模板/public/index.html'))
    const htmlResult = htmlStr.replace(/[\r\n]/g, '').replace(/\s+/g, ' ')
    const jsStr = await read(path.join(__dirname, '02_主观题/01_压缩 CSS 代码/01_模板/public/index.js'))
    const jsResult = jsStr.replace(/[\r\n]/g, '').replace(/\s+/g, ' ').replace(/console.log\(.+?\)/g, '')
    const cssStr = await read(path.join(__dirname, '02_主观题/01_压缩 CSS 代码/01_模板/public/index.css'))
    const cssResult = cssStr.replace(/[\r\n]/g, '')
    fs.writeFile(path.join(__dirname, 'index.html'), htmlResult + `<style>${cssResult}</style>` + `<script>${jsResult}</script>`, err => {
        console.log(err)
    })
}
render()